Here are some code segments to show how this is achieved:
this bit you'll probably do in the class constructor - just set up the dataset and the listbox binding rules:
_dataset = new DataSet();
_dataset.ReadXml(new StringReader(resultXML)); // resultXML is a string of xml
_listBox1.ValueMember = "id";
_listBox1.DisplayMember = "name";
_listBox1.DataSource = _dataset.Tables["address"];
Now here's how you might add a row to the table data:
/* get a reference to the listbox's source datatable */
DataTable _dataTable = (DataTable)_listBox1.DataSource;
/* create a new DataRow instance */
DataRow _row = _dataTable.NewRow();
/* assign data fields to the DataRow */
_row["id"] = "1";
_row["name"] = "fred";
_row["destination"] = "123123123";
_row["email"] = "fred@spiration.co.uk";
_row["default"] = "yes";
/* add the new row to the DataTable */
_dataTable.Rows.Add(_row);
/*
specify a sort rule for the defaultview otherwise
the new item will just appear at the bottom of the list
*/
_dataTable.DefaultView.Sort = "name";
That's all there is to it. The great simplicity here is that you only have to create a DataRow object and add it into the DataTable. There's no lisbox or item array manipulation required here. Even the sorting is managed for you.
Hope that's useful
christo